package com.itany.shop.service.impl;

import com.itany.shop.dao.ProductDao;
import com.itany.shop.entity.Product;
import com.itany.shop.factory.ObjectFactory;
import com.itany.shop.service.ProductService;
import com.itany.shop.util.PageInfo;

import java.util.List;

/**
 * @Author:石小俊
 * @Date:2022/11/16 11:17
 * @Version:1.0-SNAPSHOT
 * @Description:
 */
public class ProductServiceImpl implements ProductService {

    private ProductDao productDao = (ProductDao) ObjectFactory.getObject("productDao");

    @Override
    public List<Product> findAll() {
        List<Product> products = productDao.selectAll();
        return products;
    }

    @Override
    public List<Product> findPage(Integer pageNo, Integer pageSize) {
        List<Product> products = productDao.selectPage(pageNo,pageSize);
        return products;
    }

    @Override
    public PageInfo<Product> findPageInfo(Integer pageNo, Integer pageSize) {
        // 获取总记录数
        int count = productDao.selectCount();
        List<Product> products = productDao.selectPage(pageNo,pageSize);
        PageInfo<Product> productPage = new PageInfo<>(count,products,pageNo,pageSize);
        return productPage;
    }
}
